package common

import (
	"wish_go/src/main/com/ajie/vo"
)

func GeneratePagination(pagination vo.Pagination) vo.Pagination {
	// 校验参数
	if pagination.PageSize < 0 {
		pagination.PageSize = -1
	}
	if pagination.PageSize < 1 {
		pagination.PageSize = -1
	}
	if len(pagination.SortName) == 0 {
		pagination.SortName = "created_at desc"
	}
	return pagination
}
func GeneratePageInfo(pageInfo vo.PageInfo) vo.PageInfo {
	// 校验参数
	if pageInfo.PageSize < 0 {
		pageInfo.PageSize = -1
	}
	if pageInfo.Page < 1 {
		pageInfo.Page = -1
	}
	if len(pageInfo.SortName) == 0 {
		pageInfo.SortName = "created_at desc"
	}
	if len(pageInfo.Keywords) > 0 {
		pageInfo.Keywords = "%" + pageInfo.Keywords + "%"
	}
	return pageInfo
}
